import React, { Component } from 'react'

export default class LifeCycle1 extends Component {
    constructor() {
        super()
        this.state = {
            count: 100
        }
    }
    autoPlay=()=>{
        this.timer=setInterval(() => {
            this.setState({
                count: this.state.count - 1
            })
        }, 100);
    }
    componentDidMount() {
       this.autoPlay()
    }
    render() {
        console.log('------render-------');
        return (
            <div>
                <h1 onMouseOver={()=>{
                    //停止定时器
                    clearInterval(this.timer)
                }} onMouseOut={()=>{
                    this.autoPlay()
                }}>{this.state.count}</h1>
            </div>
        )
    }
}
